package com.sniff.atp.modules.test.process;

import com.sniff.atp.modules.test.model.DemandReport;
import com.sniff.atp.modules.test.service.DemandReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @ProjectName: sniff-atp
 * @Package: com.sniff.atp.modules.test.process
 * @ClassName: BusinessPublishPlan
 * @Description: 定时更新开发中转测试中数据
 * @Author: zss
 * @CreateDate: 2023/11/2 19:36
 * @UpdateDate: 2023/11/2 19:36
 * @Version: 1.0
 */

@Component
@Configuration
@EnableScheduling
public class DemandReportStatusUpdate {

    @Value("${sniff.autoInfoFlag}")
    private String autoInfoFlag;

    @Autowired
    private DemandReportService demandReportService;


//    @Scheduled(cron = "0/5 * * * * ?")
    @Scheduled(cron = "0 0 10 * * ?")
    private void configureTasks(){
        System.out.println("111111111111111");

        if("true".equals(autoInfoFlag)){
            // 获取当前日期
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);

            // 获取当天的0点时间的Date对象
            Date midnightDate = calendar.getTime();

            DemandReport demandReport = new DemandReport();
            demandReport.setDemandStatus("已测试");
            demandReport.setPublishDate(midnightDate);

            //查询当天还在开发中的数据
            try {
                List<DemandReport> demandReportList = demandReportService.qryDemandReportByPublishDate(demandReport);
                if(demandReportList.size() > 0){
                    //更新状态
                    int uodateNum = demandReportService.batchUpdateDemandByCode(demandReportList);
                }
            } finally {

            }

            //获取有提测时间的数据
            // 获取提测时间
            Calendar calendar2 = Calendar.getInstance();
            calendar2.set(Calendar.HOUR_OF_DAY, +1);
            calendar2.set(Calendar.MINUTE, 0);
            calendar2.set(Calendar.SECOND, 0);
            calendar2.set(Calendar.MILLISECOND, 0);

            // 获取当天的0点时间的Date对象
            Date froentDate = calendar2.getTime();
            DemandReport demandReport2 = new DemandReport();
            demandReport2.setSubmitApplicationDate(froentDate);
            //查询上一天还在开发中的数据
            try {
                List<DemandReport> demandReportList = demandReportService.qryDemandReportBySubmitDate(demandReport2);
                if(demandReportList.size() > 0){
                    //更新状态
                    int uodateNum = demandReportService.batchUpdateDemandByCode(demandReportList);
                }
            } finally {

            }
        }
    }
}
